package com.schedule.classroom.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.schedule.classroom.entity.ClassRoom;
import com.schedule.classroom.entity.ListParam;
import com.schedule.classroom.service.ClassRoomService;
import com.schedule.common.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cyljx
 */
@RestController
@RequestMapping("/api/classroom")
public class ClassRoomController {
    @Autowired
    private ClassRoomService classRoomService;


    @PostMapping
    public CommonResult<String>  add(@RequestBody ClassRoom classRoom){
        boolean save = classRoomService.save(classRoom);
        if(save){
            return CommonResult.success("新增成功!");
        }
        return CommonResult.error("新增失败!");
    }

    @PutMapping
    public CommonResult<String>  edit(@RequestBody ClassRoom classRoom){
        boolean save = classRoomService.updateById(classRoom);
        if(save){
            return CommonResult.success("编辑成功!");
        }
        return CommonResult.error("编辑失败!");
    }

    @DeleteMapping("/{roomId}")
    public CommonResult<String> delete(@PathVariable("roomId") Long roomId){
        boolean b = classRoomService.removeById(roomId);
        if(b){
            return CommonResult.success("删除成功!");
        }
        return CommonResult.error("删除失败!");
    }


    @GetMapping("/list")
    public CommonResult<IPage<ClassRoom>> getList(ListParam listParam){
        IPage<ClassRoom> list = classRoomService.getList(listParam);
        return CommonResult.success("查询成功",list);
    }

}
